﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Top.Data;

namespace Top.PointStore.Business
{
    public class BuildingManager
    {
        /// <summary>
        /// 根据行为代码获取积分配置信息
        /// </summary>
        /// <param name="buildingKid"></param>
        /// <returns></returns>
        public static async Task<int> IsExists(int buildingKid)
        {
            const string sql = "select count(1) from T_Building where Kid={0}";
            using (var db = new DbTour())
            {
                return await db.Sql(sql, buildingKid).ExecuteScalar<int>(0);
            }
        }


        /// <summary> 获取用户的楼盘
        /// </summary>
        /// <param name="buildingid">楼盘id</param>
        /// <remarks>周子鉴 2015.01.24</remarks>
        public static async Task<T_Building> GetBuilding(int buildingid)
        {
            if (buildingid <= 0)
            {
                return null;
            }
            const string sql = @"select * from T_Building where kid = {0} and F_Enable = 1";
            using (var db = new DbTour("sqldefault"))
            {
                return await db.Sql(sql, buildingid).FirstOrDefault<T_Building>();
            }
        }

        public static async Task<T_Building> GetBuilding(int buildingid, DbTour db)
        {
            if (buildingid <= 0)
            {
                return null;
            }
            const string sql = @"select * from T_Building where kid = {0} and F_Enable = 1";

            return await db.Sql(sql, buildingid).FirstOrDefault<T_Building>();

        }
    }
}
